package com.dzk.cp.c11x5.index.q2.l012.yl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.dzk.cp.c11x5.index.BaseC11x5Index;
import com.dzk.cp.c11x5.pojo.R5;
import com.dzk.cp.c11x5.util.SpringBeanUtils;

public abstract class Q2LxxYLIndex extends BaseC11x5Index {
	
	private String xx;
	
	protected Q2LxxYLIndex setParams(int code, int num, int unit, String xx) {
		super.setParams(code, num, unit);
		this.xx = xx;
		return this;
	}

	@Override
	public Map<?, Integer> index() {
		Map<Integer, Integer> resultMap = new LinkedHashMap<Integer, Integer>();
		int n = getLastestNum();
		List<? extends R5> r5s = SpringBeanUtils.getR5Service(code).queryLatest(n);
		int i = -1, j = 0, k = 0;
		for (; k < n; k++) {
			R5 r5 = r5s.get(k);
			if (r5.getN1() % 3 == xx.charAt(0) - 48 && r5.getN2() % 3 == xx.charAt(1) - 48) {
				resultMap.put(++j, k - i - 1);
				i = k;
			}
		}
		resultMap.put(++j, k - 1 - i);
		return resultMap;
	}
	
	public static Q2LxxYLIndex getInstance(int code, int num, int unit, String xx) {
		int n = (xx.charAt(0) - 48) * 3 + (xx.charAt(1) - 48);
		switch (n) {
		case 0:
			return new Q2L00YLIndex().setParams(code, num, unit, xx);
		case 1:
			return new Q2L01YLIndex().setParams(code, num, unit, xx);
		case 2:
			return new Q2L02YLIndex().setParams(code, num, unit, xx);
		case 3:
			return new Q2L10YLIndex().setParams(code, num, unit, xx);
		case 4:
			return new Q2L11YLIndex().setParams(code, num, unit, xx);
		case 5:
			return new Q2L12YLIndex().setParams(code, num, unit, xx);
		case 6:
			return new Q2L20YLIndex().setParams(code, num, unit, xx);
		case 7:
			return new Q2L21YLIndex().setParams(code, num, unit, xx);
		case 8:
			return new Q2L22YLIndex().setParams(code, num, unit, xx);
		default:
			return null;
		}
	}

}

class Q2L00YLIndex extends Q2LxxYLIndex {

	@Override
	protected int getZQ() {
		return 110 / 6;
	}
	
}

class Q2L01YLIndex extends Q2LxxYLIndex {

	@Override
	protected int getZQ() {
		return 110 / 12;
	}
	
}

class Q2L02YLIndex extends Q2LxxYLIndex {

	@Override
	protected int getZQ() {
		return 110 / 12;
	}
	
}

class Q2L10YLIndex extends Q2LxxYLIndex {

	@Override
	protected int getZQ() {
		return 110 / 12;
	}
	
}

class Q2L11YLIndex extends Q2LxxYLIndex {

	@Override
	protected int getZQ() {
		return 110 / 12;
	}
	
}

class Q2L12YLIndex extends Q2LxxYLIndex {

	@Override
	protected int getZQ() {
		return 110 / 16;
	}
	
}

class Q2L20YLIndex extends Q2LxxYLIndex {

	@Override
	protected int getZQ() {
		return 110 / 12;
	}
	
}

class Q2L21YLIndex extends Q2LxxYLIndex {

	@Override
	protected int getZQ() {
		return 110 / 16;
	}
	
}

class Q2L22YLIndex extends Q2LxxYLIndex {

	@Override
	protected int getZQ() {
		return 110 / 12;
	}
	
}
